package base.thread;

class LockDead extends Thread {
	StringBuffer f;
	StringBuffer s;

	public LockDead(StringBuffer f, StringBuffer s) {
		this.f = f;
		this.s = s;
	}

	public void run() {
		synchronized (f) {
			System.out.println("get " + f);
			synchronized (s) {
				System.out.println("get all " + f + " and " + s);
			}
		}
	}
}

public class DeadLockT {

	public static void main(String[] args) throws Exception{
		new DeadLockT().lock();
	}
	
	public void lock() throws Exception {
		StringBuffer first = new StringBuffer("hello");
		StringBuffer second = new StringBuffer("world");
		LockDead dead1=new LockDead(first, second);
		LockDead dead2=new LockDead(second, first);
		dead1.start();
		dead2.start();
		dead1.join();
		dead2.join();
		System.out.println("hhh");
	}
}
